package com.whmskj.xjlhsc.panel.service.imp;

import com.whmskj.xjlhsc.panel.mapper.WindingMapper;
import com.whmskj.xjlhsc.panel.pojo.entity.*;
import com.whmskj.xjlhsc.panel.pojo.vo.MachineOperatingEfficiency;
import com.whmskj.xjlhsc.panel.pojo.vo.WindingVO;
import com.whmskj.xjlhsc.panel.service.IWindingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.List;

/**
 * @author jiaruchun
 * @date 2025-09-13 09:07
 */
@Service
public class WindingServiceImpl implements IWindingService {
    
    @Autowired
    private WindingMapper windingMapper;

    @Override
    public WindingVO getWindingData() {
        WindingVO windingVO = new WindingVO();
        //运行效率--
        List<MachineOperatingEfficiency> machineOperatingEfficiency = windingMapper.getMachineOperatingEfficiency();
        //保留三位小数
        for (MachineOperatingEfficiency machineOperatingEfficiency1 : machineOperatingEfficiency) {
            machineOperatingEfficiency1.setEfficiency(Float.valueOf(new DecimalFormat("0.00").format(machineOperatingEfficiency1.getEfficiency() * 100)));
        }
        windingVO.setMachineOperatingEfficiency(machineOperatingEfficiency);
        //机台运行统计--
        MachineOperationStatistics machineOperationStatistics = windingMapper.getMachineOperationStatistics();
        windingVO.setMachineOperationStatistics(machineOperationStatistics);
        //上岗人员统计--
        StatisticsOfPersonnel statisticsOfPersonnel = windingMapper.getStatisticsOfPersonnel();
        windingVO.setStatisticsOfPersonnel(statisticsOfPersonnel);
//        实时温度--
        List<RealTimeTemperature> realTimeTemperature = windingMapper.getRealTimeTemperature();
        windingVO.setRealTimeTemperature(realTimeTemperature);
        //个人产量--
        List<IndividualOutput> individualOutput = windingMapper.getIndividualOutput();
        //保留三位小数
        for (IndividualOutput individualOutput1 : individualOutput) {
            individualOutput1.setOutputOnDuty(Float.valueOf(new DecimalFormat("0.000").format(individualOutput1.getOutputOnDuty())));
            individualOutput1.setCumulativeMonthlyOutput(Float.valueOf(new DecimalFormat("0.000").format(individualOutput1.getCumulativeMonthlyOutput())));
        }
        windingVO.setIndividualOutput(individualOutput);
        //月能耗--
        List<MonthlyEnergyConsumption> monthlyEnergyConsumption = windingMapper.getMonthlyEnergyConsumption();
        //保留三位小数
        for (MonthlyEnergyConsumption monthlyEnergyConsumption1 : monthlyEnergyConsumption) {
            monthlyEnergyConsumption1.setEnergyConsumptionOnDuty(Float.valueOf(new DecimalFormat("0.000").format(monthlyEnergyConsumption1.getEnergyConsumptionOnDuty())));
            monthlyEnergyConsumption1.setCumulativeEnergyConsumptionForTheMonth(Float.valueOf(new DecimalFormat("0.000").format(monthlyEnergyConsumption1.getCumulativeEnergyConsumptionForTheMonth())));
        }
        windingVO.setMonthlyEnergyConsumption(monthlyEnergyConsumption);
        return windingVO;
    }
}
